package com.sgb.kjwl.view.ui.activity.self.packers;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.util.Pair;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;

import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.decoration.GridSpacingItemDecoration;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.tools.ScreenUtils;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.AppConstant;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivitySelfTeamIntroduceBinding;
import com.sgb.kjwl.di.self.DaggerSelfComponent;
import com.sgb.kjwl.di.self.SelfModule;
import com.sgb.kjwl.model.entity.packers.BuildCompanyInfoEntity;
import com.swgk.core.util.TransObjectUtils;
import com.sgb.link.router.PathTeam;
import com.swgk.core.common.utils.ActivityJump;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.self.SelfTeamIntroduceEntity;
import com.sgb.kjwl.model.entity.transport.MapLongAndLatEntity;
import com.sgb.kjwl.model.entity.user.AddressEntity;
import com.sgb.kjwl.utils.NumberConstant;
import com.sgb.kjwl.view.ui.activity.PhotoViewActivity;
import com.sgb.alimaplibrary.SelectAddressActivity;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.sgb.kjwl.view.ui.adapter.self.packers.FlowLayoutAdapter1;
import com.sgb.link.view.adapter.SelfTeamPicAdapter;
import com.swgk.core.util.UiUtil;
import com.swgk.core.view.CityPickBuilder;
import com.swgk.core.view.CityPickView;
import com.sgb.kjwl.view.widget.MyItemDecoration;
import com.sgb.kjwl.viewmodel.self.packers.SelfTeamIntroduceModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.customview.GlideRoundTransform;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.recyclerview.FlowLayoutManager;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.inject.Inject;

/**
 * @author WYJ
 * @date 2020/8/27
 * description:工队发布
 */
public class SelfTeamIntroduceActivity extends AppActivity implements ItemInputTextView.OnWholeItemClickListener {

    @Inject
    public SelfTeamIntroduceModel mModel;
    private ActivitySelfTeamIntroduceBinding mBind;

    public SelfTeamIntroduceEntity mEntity;

    private FlowLayoutAdapter1 mAdapter1;

    private RequestManager requestManager;
    private int mCompanyType = SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0);

    /**
     * 一级联动数据
     */
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntityList;
    /**
     * 二级联动数据
     */
    private final List<List<AddressEntity<List<AddressEntity>>>> opt2 = new ArrayList<>();
    /**
     * 三级联动数据
     */
    private final List<List<List<AddressEntity>>> opt3 = new ArrayList<>();

    /**
     * 籍贯联动数据
     */
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> jgAddressEntityList;
    /**
     * 籍贯二级联动数据
     */
    private final List<List<AddressEntity<List<AddressEntity>>>> jgOpt2 = new ArrayList<>();
    /**
     * 籍贯三级联动数据
     */
    private final List<List<List<AddressEntity>>> jgOpt3 = new ArrayList<>();

    /**
     * 班组联动数据
     */
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> bzAddressEntityList;
    /**
     * 班组二级联动数据
     */
    private final List<List<AddressEntity<List<AddressEntity>>>> bzOpt2 = new ArrayList<>();
    /**
     * 班组三级联动数据
     */
    private final List<List<List<AddressEntity>>> bzOpt3 = new ArrayList<>();

    /**
     * 施工联动数据
     */
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> sgAddressEntityList;
    /**
     * 施工二级联动数据
     */
    private final List<List<AddressEntity<List<AddressEntity>>>> sgOpt2 = new ArrayList<>();
    /**
     * 施工三级联动数据
     */
    private final List<List<List<AddressEntity>>> sgOpt3 = new ArrayList<>();
    private Thread thread;
    /**
     * 籍贯
     */
    private Thread threadJg;
    /**
     * 班组
     */
    private Thread threadBz;
    /**
     * 施工
     */
    private Thread threadSg;
    private static final int MSG_LOAD_DATA = 0x0001;
    private static final int MSG_LOAD_SUCCESS = 0x0002;
    private static final int MSG_LOAD_DATA_JG = 0x0003;
    private static final int MSG_LOAD_SUCCESS_JG = 0x0004;
    private static final int MSG_LOAD_DATA_BZ = 0x0005;
    private static final int MSG_LOAD_SUCCESS_BZ = 0x0006;
    private static final int MSG_LOAD_DATA_SG = 0x0007;
    private static final int MSG_LOAD_SUCCESS_SG = 0x0008;
    private boolean isLoaded = false;
    private boolean isLoadedWhere = false;
    private boolean isLoadedBz = false;
    private boolean isLoadedSg = false;

    private int cityPosition1;
    private int cityPosition2;
    private int cityPosition3;

    private int wherePosition1;
    private int wherePosition2;
    private int wherePosition3;

    private int bzPosition1;
    private int bzPosition2;
    private int bzPosition3;

    private int sgPosition1;
    private int sgPosition2;
    private int sgPosition3;

    private boolean isCompanyRole;
    private SelfTeamPicAdapter mPicAdapter;
    private List<String> files;
    private String teamTypes;
    private final List<PickSelectEntity> pickNation = new ArrayList<>();
    private int mNationPosition, mTeamPersonNumberPos;
    private boolean haveAddress = false;

    public static void start(Context context, SelfTeamIntroduceEntity entity, int type) {
        Intent intent = new Intent(context, SelfTeamIntroduceActivity.class);
        intent.putExtra(AppConstant.EXTRA_ENTITY, entity);
        intent.putExtra(AppConstant.EXTRA_TYPE, type);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerSelfComponent.builder()
                .appComponent(appComponent)
                .selfModule(new SelfModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActionBar.setOnBackClickListener(v -> finishViewData());
    }

    @Override
    protected void initView() {
        requestManager = Glide.with(this);
        mEntity = (SelfTeamIntroduceEntity) getIntent().getSerializableExtra(AppConstant.EXTRA_ENTITY);
        if (mEntity == null) {
            mEntity = new SelfTeamIntroduceEntity();
            if (mCompanyType == 2){
                mEntity.setTeamNo(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NO, ""));
            }
        }
        mBind = DataBindingUtil.setContentView(this, R.layout.activity_self_team_introduce);
        mBind.setViewModel(mEntity);
        teamTypes = getIntent().getStringExtra("teamType");
        if (mCompanyType == 2){
            teamTypes = "";
        }
        if (TextUtils.isEmpty(teamTypes)) {
            // 首选企业编号，如果企业编号为空，则传用户编号，两者不能同时为空，不能同时都有值
            String companyNo = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NO, "");
            isCompanyRole = !"".equals(companyNo) && !"0".equals(companyNo);
            if (mCompanyType == 2){
                isCompanyRole = false;
            }
            if (!isCompanyRole) {
                // 如果是个人账号 默认工队类型为班组工队为1
                updateTeamType(new PickSelectEntity("1", getResources().getString(R.string.ti_team_type_1)));
            }
        } else {
            isCompanyRole = true;
            mModel.getTeamIntroduceData(getIntent().getStringExtra("no"));
        }
        mBind.ivPackerAvatar.setOnClickListener(this);
        mBind.btnRelease.setOnClickListener(this);
        mBind.includeOne.deleteTv.setOnClickListener(this);
        mBind.cooperationBusinessLicense.setOnClickListener(this);
        mBind.llAddBusiness.setOnClickListener(this);
        mBind.includeOne.llAdd.setOnClickListener(this);
        mBind.etNation.setOnWholeItemClickListener(this);
        mBind.etSex.setOnWholeItemClickListener(this);
        mBind.etWhere.setOnWholeItemClickListener(this);
        UiUtil.setEtFilter(mBind.includeOne.etCompanyName.content_edt, 30);
        mBind.includeOne.etManagementAddress.setOnWholeItemClickListener(this);
        mBind.cooperationAddress.setOnWholeItemClickListener(this);
        mBind.includeOne.etProxyCode.setNumberAndLetter("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
        mBind.cooperationCode.setNumberAndLetter("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
        mBind.includeOne.etRegisteredCapital.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
        mBind.cooperationCapital.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
        mBind.etAge.setInputType(InputType.TYPE_CLASS_NUMBER);
        mBind.etContacts.setInfilterType(ItemInputTextView.TYPE_NAME);
        mBind.etPhone.getContent_edt().setInputType(InputType.TYPE_CLASS_PHONE);
        mBind.etPhone.setInfilterType(ItemInputTextView.TYPE_PHONE);
        mBind.cooperationPhone.getContent_edt().setInputType(InputType.TYPE_CLASS_PHONE);
        mBind.cooperationPhone.setInfilterType(ItemInputTextView.TYPE_PHONE);
        mBind.etMemNumber.setOnWholeItemClickListener(this);

        mAdapter1 = new FlowLayoutAdapter1(this, new ArrayList<>());
        mBind.rvBusiness.setLayoutManager(new FlowLayoutManager());
        mBind.rvBusiness.addItemDecoration(new MyItemDecoration());
        mBind.rvBusiness.setAdapter(mAdapter1);

        mModel.getCustomerData(false);
        updateIntroduceEntity(mEntity);
        rvCooperationFile();

        if (mCompanyType == 0 || mCompanyType == 2) {
            mBind.etCustomer.setVisibility(View.GONE);
        } else {
            mBind.etCustomer.setVisibility(View.VISIBLE);
        }

        int companyType = SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0);
        mBind.llCooperationCompany.setVisibility(View.GONE);
        if (companyType == 0 || companyType == 2) {
            mBind.includeOne.layout.setVisibility(View.VISIBLE);
        } else {
            mBind.includeOne.layout.setVisibility(View.GONE);
        }
    }

    public void updateIntroduceEntity(SelfTeamIntroduceEntity entity) {
        mEntity = entity;
        mBind.etBusiness.setOnWholeItemClickListener(this);
        mBind.etAddress.setOnWholeItemClickListener(this);
        mBind.etArea.setOnClickListener(this);
        mBind.etCustomer.setOnWholeItemClickListener(this);
        mBind.etCategoryName.setOnClickListener(this);
        mBind.etTeamType.setOnWholeItemClickListener(this);
        mBind.setViewModel(mEntity);
        if (mEntity != null) {
            RequestOptions options = new RequestOptions()
                    .placeholder(R.mipmap.packer_avatar)
                    .transforms(new CenterCrop(), new RoundedCorners(8));
            if (TextUtils.isEmpty(mEntity.getAvatarAddress())) {
                requestManager.load(R.mipmap.packer_avatar).into(mBind.ivPackerAvatar);
            } else {
                requestManager.load(mEntity.getAvatarAddress()).apply(options).into(mBind.ivPackerAvatar);
            }
            if (mEntity.getBusinessScopes() != null && mEntity.getBusinessScopes().size() > 0) {
                mBind.etBusiness.getContent_edt().setHint("");
            } else {
                mBind.etBusiness.getContent_edt().setHint("请选择主营业务");
            }
            if (mEntity.getServiceAreas() != null && mEntity.getServiceAreas().size() > 0) {
                mBind.etArea.setHint("");
            } else {
                mBind.etArea.setHint("请选择工作区域");
            }
            mAdapter1.setDatas(mEntity.getBusinessScopes());
            StringBuilder stringBuilder = new StringBuilder();
            for (SelfTeamIntroduceEntity.ServiceAreasBean serviceArea : (entity.getServiceAreas() == null ? new ArrayList<SelfTeamIntroduceEntity.ServiceAreasBean>() : entity.getServiceAreas())) {
                stringBuilder.append("/").append(serviceArea.getName());
            }
            stringBuilder.delete(0,1);
            mBind.etArea.setText(stringBuilder.toString());
            if (!TextUtils.isEmpty(entity.getProvinceName())) {
                mBind.etAddress.setContent(entity.getProvinceName() + entity.getCityName() + entity.getAreaName());
            }
        } else {
            mEntity = new SelfTeamIntroduceEntity();
            if (!isCompanyRole) {
                // 如果是个人账号 默认工队类型为班组工队为1
                updateTeamType(new PickSelectEntity("1", getResources().getString(R.string.ti_team_type_1)));
            }
        }
    }

    @Override
    public void onMultiClick(View v) {
        int id = v.getId();
        if (id == R.id.delete_tv) {
            mEntity.setAffiliatedUnitPic("");
            mBind.includeOne.deleteTv.setVisibility(View.GONE);
            mBind.includeOne.img.setVisibility(View.GONE);
        } else if (id == R.id.ll_add_business) {
            mModel.CooperationBusinessLicenseSelector();
        } else if (id == R.id.iv_packer_avatar) {
            mModel.pictureSelector();
        } else if (id == R.id.cooperation_business_license) {
            List<String> list = new ArrayList<>();
            list.add(mEntity.getBusinessLicense());
            Intent intent = new Intent(getActivity(), PhotoViewActivity.class);
            intent.putExtra(PhotoViewActivity.KEY_PHOTO_URLS, (Serializable) list);
            startActivity(intent);
        } else if (id == R.id.et_categoryName) {
            mModel.showPop(v);
        } else if (id == R.id.et_area) {
            // 服务地区
            SelfServiceAreaActivity.start(this, mEntity.getServiceAreas(), AppConstant.REQ_SERVICE, "工作区域");
        } else if (id == R.id.ll_add) {
            mModel.affiliatedUnitPic();
        } else if (id == R.id.team_publish) {
            updateIntroduceEntity(null);
        } else if (id == R.id.btn_release) {
            if (files == null) {
                files = new ArrayList<>();
            }

            files.clear();

            if (isCompanyRole && TextUtils.isEmpty(mBind.etTeamType.getContent())) {
                MToast.showToast(this, mBind.etTeamType.getContent_edt().getHint().toString());
                return;
            }

            if (TextUtils.isEmpty(mBind.etCategoryName.getText().toString())) {
                MToast.showToast(this, mBind.etCategoryName.getHint().toString());
                return;
            }

            if (TextUtils.isEmpty(mBind.etArea.getText().toString())) {
                MToast.showToast(this, mBind.etArea.getHint().toString());
                return;
            }

            if (TextUtils.isEmpty(mBind.etAddress.getContent())) {
                MToast.showToast(this, mBind.etAddress.getContent_edt().getHint().toString());
                return;
            }

            if (TextUtils.isEmpty(mBind.etContacts.getContent())) {
                MToast.showToast(this, mBind.etContacts.getContent_edt().getHint().toString());
                return;
            }

            if (TextUtils.isEmpty(mBind.etPhone.getContent())) {
                MToast.showToast(this, mBind.etPhone.getContent_edt().getHint().toString());
                return;
            }

            if (!CheckUtils.isMobile(mBind.etPhone.getContent().trim())) {
                Toast.makeText(this, "请填写正确的联系电话", Toast.LENGTH_SHORT).show();
                return;
            }

            if (getString(R.string.app_zero).equals(mBind.etMemNumber.getContent())) {
                MToast.showToast(this, "请输入正确的团队人数");
                return;
            }

            if (getString(R.string.app_zero).equals(mBind.etAge.getContent())) {
                MToast.showToast(this, "请输入正确的年龄");
                return;
            }

            if (mBind.etContacts.getContent().length() < NumberConstant.NUMBER_TWO) {
                MToast.showToast(this, "姓名最少输入两位数");
                return;
            }

            if (TextUtils.isEmpty(mBind.etBasic.getEditContent())) {
                MToast.showToast(this, "请填写工队简介");
                return;
            }

            String[] split = mBind.etCategoryName.getText().toString().split("\\|");
            switch (mEntity.getTeamType()) {
                case 0:
                    mEntity.setTeamName(mBind.etContacts.getContent() + "-" + split[split.length - 1] + "-" + "施工队");
                    break;
                case 1:
                    mEntity.setTeamName(mBind.etContacts.getContent() + "-" + split[split.length - 1] + "-" + "班组工队");
                    break;
                case 2:
                    mEntity.setTeamName(mBind.cooperationCompanyname.getContent() + "(" + split[split.length - 1] + ")");
                    break;
            }
            mEntity.setContact(mBind.etContacts.getContent());
            String temp = mBind.etPhone.getContent();
            if (mBind.etPhone.getContent().startsWith("+86")) {
                temp = mBind.etPhone.getContent().substring(3);
            }
            mEntity.setPhoneNumber(temp);
            mEntity.setBasicSituation(mBind.etBasic.getEditContent());
            mEntity.setTeamHistory(mBind.etHistory.getEditContent());
            mEntity.setManageStructure(mBind.etStructure.getEditContent());
            mEntity.setBusinessPhil(mBind.etIdea.getEditContent());
            List<SelfTeamIntroduceEntity.ServiceAreasBean> beans = new ArrayList<>();
            if (mEntity.getServiceAreas() != null && mEntity.getServiceAreas().size() > 0) {
                beans.addAll(mEntity.getServiceAreas());
            }
            mEntity.setServiceAreas(beans);
            // 0  施工队  1  班组
            if (mEntity.getTeamType() != 0) {
                mEntity.setLegalName("");
                mEntity.setBusinessLicense("");
                mEntity.setLegalPhone("");
                mEntity.setCreditCode("");
                mEntity.setLegalComName("");
                mEntity.setRegisteredCapital("");
                mEntity.setFilePath(new ArrayList<>());
                mEntity.setTrustCompany("");
                mEntity.setBusinessAddress(null);
                mEntity.setBusinessAddress1("");
                mEntity.setBusinessAddressName("");
                //隶属单位
                if (!TextUtils.isEmpty(mBind.includeOne.etCompanyName.getContent())) {//2.10.0.1改成传文字
                    mEntity.setAffiliatedUnitPic(mBind.includeOne.etCompanyName.getContent());
                }
                //v2.8.9新增字段
                //法人
                mEntity.setLegalPerson(mBind.includeOne.etLegalPerson.getContent().trim());
                //代征证号
                mEntity.setCertificateNumber(mBind.includeOne.etProxyCode.getContent().trim());
                //注册资金
                mEntity.setAffRegisteredCapital(mBind.includeOne.etRegisteredCapital.getContent().trim());
                try {
                    mModel.addTeamInfo(mEntity);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            } else {
                if (TextUtils.isEmpty(mBind.cooperationCompanyname.getContent())) {
                    MToast.showToast(this, "请输入公司名称");
                    return;
                }
                if (TextUtils.isEmpty(mBind.cooperationName.getContent())) {
                    MToast.showToast(this, "请输入法人名称");
                    return;
                }
                if (TextUtils.isEmpty(mBind.cooperationPhone.getContent())) {
                    MToast.showToast(this, "请输入联系电话");
                    return;
                }
                if (TextUtils.isEmpty(mBind.cooperationCode.getContent())) {
                    MToast.showToast(this, "请输入统一社会信用代码");
                    return;
                }
                if (TextUtils.isEmpty(mBind.cooperationCapital.getContent())) {
                    MToast.showToast(this, "请输入注册资本");
                    return;
                }
                if (TextUtils.isEmpty(mBind.cooperationAddress.getContent())) {
                    MToast.showToast(this, "请输入经营地址");
                    return;
                }

                if (TextUtils.isEmpty(mEntity.getBusinessLicense())) {
                    MToast.showToast(this, "请上传营业执照");
                    return;
                }

                //v2.8.9新增字段
                //法人
                mEntity.setLegalPerson("");
                //代征证号
                mEntity.setCertificateNumber("");
                //经营地址
                mEntity.setAffBusinessAddress(null);
                mEntity.setAffBusinessAddressName(null);
                //注册资金
                mEntity.setAffRegisteredCapital("");


                mEntity.setAffRegisteredCapital("");
                mEntity.setLegalComName(mBind.cooperationCompanyname.getContent().trim());
                mEntity.setLegalName(mBind.cooperationName.getContent().trim());
                mEntity.setLegalPhone(mBind.cooperationPhone.getContent().trim());
                mEntity.setCreditCode(mBind.cooperationCode.getContent().trim());
                mEntity.setRegisteredCapital(mBind.cooperationCapital.getContent().trim());
                //一次上传图片
                if (mPicAdapter.getDatas().size() > 1) {
                    for (String data : mPicAdapter.getDatas()) {
                        if (!TextUtils.equals(data, "add")) {
                            if (!data.contains("http")) {
                                File file = new File(data);
                                mModel.uploadAvatarFileModel(file, 1, 3);
                            } else {
                                if (files == null) {
                                    files = new ArrayList<>();
                                }
                                files.add(data);
                                if (files.size() == mPicAdapter.getRealCount()) {
                                    try {
                                        mEntity.setFilePath(files);
                                        mModel.addTeamInfo(mEntity);
                                    } catch (IllegalAccessException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }
                    }
                } else {
                    try {
                        mEntity.setFilePath(new ArrayList<>());
                        mModel.addTeamInfo(mEntity);
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    private void rvCooperationFile() {
        List<String> tempData = new ArrayList<>();
        if (mEntity.getFilePath() != null && mEntity.getFilePath().size() > 0) {
            tempData.addAll(mEntity.getFilePath());
        }
        GridLayoutManager manager = new GridLayoutManager(this, 4);
        mBind.rvCooperationFile.setLayoutManager(manager);
        mPicAdapter = new SelfTeamPicAdapter(this, tempData, 9, manager);
        mBind.rvCooperationFile.setHasFixedSize(false);
        mBind.rvCooperationFile.addItemDecoration(new GridSpacingItemDecoration(4, ScreenUtils.dip2px(this, 5), false));
        mBind.rvCooperationFile.setAdapter(mPicAdapter);
        mPicAdapter.setOnItemClick(new AdapterOnItemClick<String>() {
            @Override
            public void onItemClick(String s, int position) {
                if (TextUtils.isEmpty(s)) {
                    mModel.rvCooperationFileList(mPicAdapter.hasCount());
                } else {
                    Intent intent = new Intent(getActivity(), PhotoViewActivity.class);
                    intent.putExtra(PhotoViewActivity.KEY_PHOTO_URLS, (Serializable) mPicAdapter.getRealData());
                    intent.putExtra(PhotoViewActivity.KEY_PHOTO_POSITION, position);
                    startActivity(intent);
                }
            }
        });
    }

    @Override
    public void OnWholeItemClick(View view) {
        int id = view.getId();
        if (id == R.id.et_business) {
            // 主营业务
            SelfMainBusinessActivity.start(this, mEntity.getBusinessScopes(), AppConstant.REQ_BUSINESS);
        } else if (id == R.id.et_address) {
            // 所在地区
            if (addressEntityList != null) {
                showCityPop();
            } else {
                mModel.getAddressModel(1);
            }
        } else if (id == R.id.et_where) {
            // 籍贯
            if (jgAddressEntityList != null) {
                showWherePop();
            } else {
                mModel.getAddressModel(0);
            }
        } else if (id == R.id.et_management_address) {
            // 班主工队经营地区
            if (!haveAddress) {
                if (bzAddressEntityList != null) {
                    showBzPop();
                } else {
                    mModel.getAddressModel(2);
                }
            }
        } else if (id == R.id.cooperation_address) {
            // 施工队经营地区
            if (!haveAddress) {
                if (sgAddressEntityList != null) {
                    showSgPop();
                } else {
                    mModel.getAddressModel(3);
                }
            }
        } else if (id == R.id.et_customer) {
            // 咨询客服
            if (mEntity.getImId() != null && mEntity.getImName() != null && mEntity.getDepartmentId() != null) {
                ActivityJump.startActivityForResult(this, AppConstant.ONLINE_LINKMAN, PathTeam.OnLineLinkActivity, Pair.create("imId", mEntity.getImId()), Pair.create("imName", mEntity.getImName()), Pair.create("departmentId", mEntity.getDepartmentId()));
            } else {
                ActivityJump.startActivityForResult(this, AppConstant.ONLINE_LINKMAN, PathTeam.OnLineLinkActivity);
            }
        } else if (id == R.id.et_team_type) {
            // 工队类型
            if (isCompanyRole) {
                mModel.showTeamTypePop();
            }
        } else if (id == R.id.et_nation) {
            if (pickNation.size() == 0) {
                mModel.getNationList();
            } else {
                showNationPop();
            }
        } else if (id == R.id.et_sex) {
            showSexPop();
        } else if (id == R.id.et_memNumber) {
            showTeamPersonNumberPop(mModel.getTeam());
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case AppConstant.REQ_BUSINESS:
                if (data != null) {
                    mEntity.setBusinessScopes((List<SelfTeamIntroduceEntity.BusinessScopesBean>) data.getSerializableExtra(AppConstant.EXTRA_OBJ));
                    mAdapter1.setDatas(mEntity.getBusinessScopes());
                    if (mEntity.getBusinessScopes() != null && mEntity.getBusinessScopes().size() > 0) {
                        mBind.etBusiness.getContent_edt().setHint("");
                    } else {
                        mBind.etBusiness.getContent_edt().setHint("请选择主营业务");
                    }
                }
                break;
            case AppConstant.REQ_SERVICE:
                if (data != null) {
                    mEntity.setServiceAreas((List<SelfTeamIntroduceEntity.ServiceAreasBean>) data.getSerializableExtra(AppConstant.EXTRA_OBJ));
                    StringBuilder stringBuilder = new StringBuilder();
                    for (SelfTeamIntroduceEntity.ServiceAreasBean serviceArea : mEntity.getServiceAreas()) {
                        stringBuilder.append("/").append(serviceArea.getName());
                    }
                    stringBuilder.delete(0,1);
                    mBind.etArea.setText(stringBuilder.toString());
                    if (mEntity.getServiceAreas() != null && mEntity.getServiceAreas().size() > 0) {
                        mBind.etArea.setHint("");
                    } else {
                        mBind.etArea.setHint("请选择工作区域");
                    }
                }
                break;
            case PictureConfig.CHOOSE_REQUEST:
                List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                RequestOptions options = new RequestOptions();
                options.transform(new GlideRoundTransform(this, 5));
                Glide.with(this).load(selectList.get(0).getRealPath()).apply(options).into(mBind.ivPackerAvatar);
                String avatar = selectList.get(0).getRealPath();
                File file = new File(avatar);
                mModel.uploadAvatarFileModel(file, 1, 1);
                break;
            case AppConstant.BUSINESS_LICENSE:
                List<LocalMedia> selectList2 = PictureSelector.obtainMultipleResult(data);
                RequestOptions options2 = new RequestOptions();
                options2.transform(new GlideRoundTransform(this, 5));
                mBind.cooperationBusinessLicense.setVisibility(View.VISIBLE);
                Glide.with(this).load(selectList2.get(0).getRealPath()).apply(options2).into(mBind.cooperationBusinessLicense);
                String businessLicense = selectList2.get(0).getRealPath();
                File file2 = new File(businessLicense);
                mModel.uploadAvatarFileModel(file2, 1, 2);
                break;
            case AppConstant.AFFILIATED_PIC:
                List<LocalMedia> selectList3 = PictureSelector.obtainMultipleResult(data);
                RequestOptions options3 = new RequestOptions();
                options3.transform(new GlideRoundTransform(this, 5));
                Glide.with(this).load(selectList3.get(0).getRealPath()).apply(options3).into(mBind.includeOne.img);
                String affiliatedUnitPic = selectList3.get(0).getRealPath();
                File file3 = new File(affiliatedUnitPic);
                mBind.includeOne.deleteTv.setVisibility(View.VISIBLE);
                mBind.includeOne.img.setVisibility(View.VISIBLE);
                mModel.uploadAvatarFileModel(file3, 1, 4);
                break;
            case AppConstant.COOPERATION_FILE:
                List<LocalMedia> selectList4 = PictureSelector.obtainMultipleResult(data);
                mPicAdapter.setPicData(selectList4);
                break;
            case 255:
                if (data == null) {
                    return;
                }
                setAddressText(data);
                break;
            case AppConstant.ONLINE_LINKMAN:
                String imId = data.getStringExtra("mImId");
                String imName = data.getStringExtra("mImName");
                String departmentId = data.getStringExtra("mDepartmentId");
                mEntity.setImName(imName);
                mEntity.setImId(imId);
                mEntity.setDepartmentId(departmentId);
                mBind.etCustomer.setContent(imName);
                break;
            default:
                break;
        }
    }

    public void setAddressText(Intent data) {
        double lat = data.getDoubleExtra(SelectAddressActivity.LATITUDE, 0);
        double lon = data.getDoubleExtra(SelectAddressActivity.LONGTITUDE, 0);
        String address = data.getStringExtra(SelectAddressActivity.CURRENT_POSITION);
        mEntity.setLongitude(lon + "");
        mEntity.setLatitude(lat + "");
        mEntity.setAddress(address);
    }

    /**
     * 上传头像回调
     *
     * @param toString
     * @param type
     */
    public void uploadAvatarResult(String toString, int type) {
        if (type == 1) {
            mEntity.setAvatarAddress(toString);
        } else if (type == 3) {
            if (files == null) {
                files = new ArrayList<>();
            }
            files.add(toString);
            if (files.size() == (mPicAdapter.getDatas().size() == 9 ? mPicAdapter.getDatas().size() : mPicAdapter.getDatas().size() - 1)) {
                mEntity.setFilePath(files);
                try {
                    mModel.addTeamInfo(mEntity);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        } else if (type == 4) {
            mEntity.setAffiliatedUnitPic(toString);
        } else {
            mEntity.setBusinessLicense(toString);
        }
    }

    public void editEntitySuccess() {
        finishViewData();
    }

    private void finishViewData() {
        if (!TextUtils.isEmpty(getIntent().getStringExtra("type")) && "webH5".equals(getIntent().getStringExtra("type"))) {
            //H5处理
            mModel.TeamParticulars(getIntent().getStringExtra("no"));
        } else {
            setResult(RESULT_OK);
            finish();
        }
    }

    public void updateAddress(MapLongAndLatEntity data) {
        if (!TextUtils.isEmpty(data.getLat())) {
            if (!TextUtils.isEmpty(data.getLng())) {
                //2.8.7只要区域经纬度
                mEntity.setLongitude(data.getLng() + "");
                mEntity.setLatitude(data.getLat() + "");
            }
        }
    }

    public void updateCustomer(PickSelectEntity serviceEntity) {
        mEntity.setImName(serviceEntity.getProjectscale());
        mEntity.setImId(serviceEntity.getNo());
        mBind.etCustomer.setContent(serviceEntity.getProjectscale());
    }

    /**
     * 工队类型
     *
     * @param entity
     */
    public void updateTeamType(PickSelectEntity entity) {
        String companyNo = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NO, "");
        if (mCompanyType != 0){
            mModel.companyInfo(companyNo);
        }
        mEntity.setTeamType(Integer.parseInt(entity.getNo()));
        mBind.etTeamType.setContent(entity.getProjectscale());
        //用来控制是否展示合作企业信息处理
        if ("施工队".equals(mBind.etTeamType.getContent())) {
            mBind.llCooperationCompany.setVisibility(View.VISIBLE);
            mBind.includeOne.layout.setVisibility(View.GONE);
        } else {
            mBind.llCooperationCompany.setVisibility(View.GONE);
            mBind.includeOne.layout.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected void onDestroy() {
        mModel.release();
        super.onDestroy();
    }


    public void setNationData(List<PickSelectEntity> list) {
        pickNation.addAll(list);
        showNationPop();
    }

    public void companyInfo(BuildCompanyInfoEntity list) {
        if (!TextUtils.isEmpty(list.getName())) {
            mBind.includeOne.etCompanyName.setContent(list.getName());
            mBind.includeOne.etCompanyName.setEnable(false);
            mBind.cooperationCompanyname.setContent(list.getName());
            mBind.cooperationCompanyname.setEnable(false);
        }

        if (!TextUtils.isEmpty(list.getLegalRepresentative())) {
            mBind.includeOne.etLegalPerson.setContent(list.getLegalRepresentative());
            mBind.includeOne.etLegalPerson.setEnable(false);
            mBind.cooperationName.setContent(list.getLegalRepresentative());
            mBind.cooperationName.setEnable(false);
        }

        if (!TextUtils.isEmpty(list.getContactNumber())) {
            mBind.cooperationPhone.setContent(list.getContactNumber());
            mBind.cooperationPhone.setEnable(false);
        }

        if (!TextUtils.isEmpty(list.getAddress())) {
            mBind.cooperationAddress.setContent(String.format("%s%s%s", list.getProvinceName(), list.getCityName(), list.getDistrictName()));
            mBind.cooperationAddress.setEnable(false);
            mBind.includeOne.etManagementAddress.setContent(String.format("%s%s%s", list.getProvinceName(), list.getCityName(), list.getDistrictName()));
            mBind.includeOne.etManagementAddress.setEnable(false);

            if ("施工队".equals(mBind.etTeamType.getContent())) {
                List<String> codeList = new ArrayList<>();
                codeList.add(list.getProvinceNo());
                codeList.add(list.getCityNo());
                codeList.add(list.getDistrictNo());
                mEntity.setBusinessAddress(codeList);
                mEntity.setBusinessAddress1(codeList.toString());
                mEntity.setBusinessAddressName(list.getAddress());
            }else {
                List<String> codeList1 = new ArrayList<>();
                codeList1.add(list.getProvinceNo());
                codeList1.add(list.getCityNo());
                codeList1.add(list.getDistrictNo());
                mEntity.setAffBusinessAddress(codeList1);
                mEntity.setAffBusinessAddressStr(codeList1.toString());
                mEntity.setAffBusinessAddressName(list.getAddress());
            }

            haveAddress = true;
        }

        if (!TextUtils.isEmpty(list.getRegisteredCapital())) {
            mBind.cooperationCapital.setContent(list.getRegisteredCapital());
            mBind.cooperationCapital.setEnable(false);
            mBind.includeOne.etRegisteredCapital.setContent(list.getRegisteredCapital());
            mBind.includeOne.etRegisteredCapital.setEnable(false);
        }

        if (!TextUtils.isEmpty(list.getAttr2())) {
            mBind.cooperationCode.setContent(list.getAttr2());
            mBind.cooperationCode.setEnable(false);
        }

        if (!TextUtils.isEmpty(list.getYyphoto())) {
            mBind.ivAdd.setVisibility(View.INVISIBLE);
            mBind.cooperationBusinessLicense.setVisibility(View.VISIBLE);
            Glide.with(getActivity()).load(list.getYyphoto()).into(mBind.cooperationBusinessLicense);
            mEntity.setBusinessLicense(list.getYyphoto());
        }
    }

    /**
     * 民族pop
     */
    public void showNationPop() {
        if (pickNation.size() > 0) {
            OptionsPickerView projectCategoryOption = new OptionsPickerBuilder(SelfTeamIntroduceActivity.this, (options1, options2, options3, v) -> {
                mBind.etNation.setContent(pickNation.get(options1).getProjectscale());
                mNationPosition = options1;
                mEntity.setPrincipalNationName(pickNation.get(options1).getProjectscale());
                mEntity.setPrincipalNation(pickNation.get(options1).getNo());
            }).setCancelColor(ContextCompat.getColor(this, R.color.color_666666)).build();
            projectCategoryOption.setPicker(pickNation);
            projectCategoryOption.setSelectOptions(mNationPosition);
            projectCategoryOption.show();
        }
    }

    /**
     * 团队人数pop
     */
    public void showTeamPersonNumberPop(List<PickSelectEntity> teamPersonNumber) {
        if (teamPersonNumber.size() > 0) {
            OptionsPickerView projectCategoryOption = new OptionsPickerBuilder(SelfTeamIntroduceActivity.this, (options1, options2, options3, v) -> {
                mBind.etMemNumber.setContent(teamPersonNumber.get(options1).getProjectscale());
                mTeamPersonNumberPos = options1;
                mEntity.setTeamNumber(teamPersonNumber.get(options1).getProjectscale());
            }).setCancelColor(ContextCompat.getColor(this, R.color.color_666666)).build();
            projectCategoryOption.setPicker(teamPersonNumber);
            projectCategoryOption.setSelectOptions(mTeamPersonNumberPos);
            projectCategoryOption.setTitleText("选择团队人数");
            projectCategoryOption.show();
        }
    }

    private int sexPosition;

    /**
     * 性别pop
     */
    public void showSexPop() {
        OptionsPickerView projectCategoryOption = new OptionsPickerBuilder(SelfTeamIntroduceActivity.this, (options1, options2, options3, v) -> {
            mBind.etSex.setContent(mModel.getSex().get(options1).getProjectscale());
            sexPosition = options1;
            mEntity.setPrincipalSex(mModel.getSex().get(options1).getNo());
        }).setCancelColor(ContextCompat.getColor(this, R.color.color_666666)).build();
        projectCategoryOption.setPicker(mModel.getSex());
        projectCategoryOption.setSelectOptions(sexPosition);
        projectCategoryOption.show();
    }

    //所在地区选择
    public void showAddressPop(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data, int type) {
        if (type == 0) {
            this.jgAddressEntityList = data;
            if (isLoadedWhere) {
                showWherePop();
            } else {
                mHandler.sendEmptyMessage(MSG_LOAD_DATA_JG);
            }
        } else if (type == 1) {
            this.addressEntityList = data;
            if (isLoaded) {
                showCityPop();
            } else {
                mHandler.sendEmptyMessage(MSG_LOAD_DATA);
            }
        } else if (type == 2) {
            this.bzAddressEntityList = data;
            if (isLoadedBz) {
                showBzPop();
            } else {
                mHandler.sendEmptyMessage(MSG_LOAD_DATA_BZ);
            }
        } else if (type == 3) {
            this.sgAddressEntityList = data;
            if (isLoadedSg) {
                showSgPop();
            } else {
                mHandler.sendEmptyMessage(MSG_LOAD_DATA_SG);
            }
        }
    }

    @SuppressWarnings("unchecked")
    public void showCityPop() {
        //条件选择器
        CityPickView cityOption = new CityPickBuilder(SelfTeamIntroduceActivity.this, (options1, options2, options3, v) -> {
            String areaName;
            if (opt3.get(options1).get(options2).get(options3) == null) {
                areaName = "";
            } else {
                areaName = opt3.get(options1).get(options2).get(options3).getName();
                cityPosition3 = options3;
                mEntity.setAreaNo(opt3.get(options1).get(options2).get(options3).getNo());
                mEntity.setAreaName(areaName);
            }
            String content = addressEntityList.get(options1).getName()
                    + opt2.get(options1).get(options2).getName()
                    + areaName;
            mBind.etAddress.setContent(content);
            cityPosition1 = options1;
            cityPosition2 = options2;
            mEntity.setProvinceName(addressEntityList.get(options1).getName());
            mEntity.setProvinceNo(addressEntityList.get(options1).getId());
            mEntity.setCityName(opt2.get(options1).get(options2).getName());
            mEntity.setCityNo(opt2.get(options1).get(options2).getNo());
            mModel.getLocationLL(mEntity.getProvinceNo(), mEntity.getCityNo(), mEntity.getAreaNo());
        }).setCancelColor(ContextCompat.getColor(this, R.color.color_666666)).build();
        cityOption.setPicker(addressEntityList, opt2, opt3);
        cityOption.setSelectOptions(cityPosition1, cityPosition2, cityPosition3);
        cityOption.show();
    }

    @SuppressWarnings("unchecked")
    public void showWherePop() {
        //条件选择器
        CityPickView cityOption = new CityPickBuilder(SelfTeamIntroduceActivity.this, (options1, options2, options3, v) -> {
            String content = jgAddressEntityList.get(options1).getName()
                    + jgOpt2.get(options1).get(options2).getName();
            List<String> codeList = new ArrayList<>();
            codeList.add(jgAddressEntityList.get(options1).getNo());
            codeList.add(jgOpt2.get(options1).get(options2).getNo());
            mEntity.setPrincipalHometown(codeList);
            if (codeList.size() == 0) {
                mEntity.setPrincipalHometownStr("");
            } else {
                mEntity.setPrincipalHometownStr(codeList.toString());
            }
            mEntity.setPrincipalHometownName(content);
            mBind.etWhere.setContent(content);
            wherePosition1 = options1;
            wherePosition2 = options2;
        }).setCancelColor(ContextCompat.getColor(this, R.color.color_666666)).build();
        cityOption.setPicker(jgAddressEntityList, jgOpt2, null);
        cityOption.setSelectOptions(wherePosition1, wherePosition2, wherePosition3);
        cityOption.show();
    }

    @SuppressWarnings("unchecked")
    public void showBzPop() {
        //条件选择器
        CityPickView cityOption = new CityPickBuilder(SelfTeamIntroduceActivity.this, (options1, options2, options3, v) -> {
            String areaName;
            String areaNo;
            if (bzOpt3.get(options1).get(options2).get(options3) == null) {
                areaName = "";
                areaNo = "";
            } else {
                areaName = bzOpt3.get(options1).get(options2).get(options3).getName();
                areaNo = bzOpt3.get(options1).get(options2).get(options3).getNo();
                bzPosition3 = options3;
            }
            String content = bzAddressEntityList.get(options1).getName()
                    + bzOpt2.get(options1).get(options2).getName()
                    + areaName;
            List<String> codeList = new ArrayList<>();
            codeList.add(bzAddressEntityList.get(options1).getNo());
            codeList.add(bzOpt2.get(options1).get(options2).getNo());
            codeList.add(areaNo);
            mEntity.setAffBusinessAddress(codeList);
            mEntity.setAffBusinessAddressStr(codeList.toString());
            mEntity.setAffBusinessAddressName(content);
            mBind.includeOne.etManagementAddress.setContent(content);
            bzPosition1 = options1;
            bzPosition2 = options2;
        }).setCancelColor(ContextCompat.getColor(this, R.color.color_666666)).build();
        cityOption.setPicker(bzAddressEntityList, bzOpt2, bzOpt3);
        cityOption.setSelectOptions(bzPosition1, bzPosition2, bzPosition3);
        cityOption.show();
    }

    @SuppressWarnings("unchecked")
    public void showSgPop() {
        //条件选择器
        CityPickView cityOption = new CityPickBuilder(SelfTeamIntroduceActivity.this, (options1, options2, options3, v) -> {
            String areaName;
            String areaNo;
            if (sgOpt3.get(options1).get(options2).get(options3) == null) {
                areaName = "";
                areaNo = "";
            } else {
                areaName = sgOpt3.get(options1).get(options2).get(options3).getName();
                areaNo = sgOpt3.get(options1).get(options2).get(options3).getNo();
                sgPosition3 = options3;
            }
            String content = sgAddressEntityList.get(options1).getName()
                    + sgOpt2.get(options1).get(options2).getName()
                    + areaName;
            List<String> codeList = new ArrayList<>();
            codeList.add(sgAddressEntityList.get(options1).getNo());
            codeList.add(sgOpt2.get(options1).get(options2).getNo());
            codeList.add(areaNo);
            mEntity.setBusinessAddress(codeList);
            mEntity.setBusinessAddress1(codeList.toString());
            mEntity.setBusinessAddressName(content);
            mBind.cooperationAddress.setContent(content);
            sgPosition1 = options1;
            sgPosition2 = options2;
        }).setCancelColor(ContextCompat.getColor(this, R.color.color_666666)).build();
        cityOption.setPicker(sgAddressEntityList, sgOpt2, sgOpt3);
        cityOption.setSelectOptions(sgPosition1, sgPosition2, sgPosition3);
        cityOption.show();
    }

    private final Handler mHandler = new Handler(new Handler.Callback() {
        @Override
        public boolean handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_LOAD_DATA:
                    if (thread == null) {//如果已创建就不再重新创建子线程了
                        // 子线程中解析省市区数据
                        thread = new Thread(() -> initJsonData());
                        thread.start();
                    }
                    break;
                case MSG_LOAD_SUCCESS:
                    showCityPop();
                    isLoaded = true;
                    thread = null;
                    break;
                case MSG_LOAD_DATA_JG:
                    if (threadJg == null) {//如果已创建就不再重新创建子线程了
                        // 子线程中解析省市区数据
                        threadJg = new Thread(() -> initJsonDataJg());
                        threadJg.start();
                    }
                    break;
                case MSG_LOAD_SUCCESS_JG:
                    showWherePop();
                    isLoadedWhere = true;
                    threadJg = null;
                    break;
                case MSG_LOAD_DATA_BZ:
                    if (threadBz == null) {//如果已创建就不再重新创建子线程了
                        // 子线程中解析省市区数据
                        threadBz = new Thread(() -> initJsonDataBz());
                        threadBz.start();
                    }
                    break;
                case MSG_LOAD_SUCCESS_BZ:
                    showBzPop();
                    isLoadedBz = true;
                    threadBz = null;
                    break;
                case MSG_LOAD_DATA_SG:
                    if (threadSg == null) {//如果已创建就不再重新创建子线程了
                        // 子线程中解析省市区数据
                        threadSg = new Thread(() -> initJsonDataSg());
                        threadSg.start();
                    }
                    break;
                case MSG_LOAD_SUCCESS_SG:
                    showSgPop();
                    isLoadedSg = true;
                    threadSg = null;
                    break;
                default:
                    break;
            }
            return false;
        }
    });

    private void initJsonData() {
        try {
            //城市列表
            @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") List<AddressEntity<List<AddressEntity>>> cityList;
            //区域列表
            List<List<AddressEntity>> areaList;
            for (int x = 0; x < addressEntityList.size(); x++) {
                cityList = new ArrayList<>();
                areaList = new ArrayList<>();
                if (mEntity != null && mEntity.getProvinceName() != null && mEntity.getProvinceName().equals(addressEntityList.get(x).getName())) {
                    cityPosition1 = x;
                }
                opt2.add(addressEntityList.get(x).getChildren());
                for (int i = 0; i < addressEntityList.get(x).getChildren().size(); i++) {
                    cityList.add(addressEntityList.get(x).getChildren().get(i));
                    List<AddressEntity> cityAreaList = new ArrayList<>();
                    //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                    if (addressEntityList.get(x).getChildren().get(i).getChildren() == null
                            || addressEntityList.get(x).getChildren().get(i).getChildren().size() == 0) {
                        cityAreaList.add(null);
                    } else {
                        cityAreaList.addAll(addressEntityList.get(x).getChildren().get(i).getChildren());
                    }
                    areaList.add(cityAreaList);
                }
                opt3.add(areaList);
            }
            if (mEntity != null) {
                if (mEntity.getCityName() != null) {
                    for (int x2 = 0; x2 < opt2.size(); x2++) {
                        if (mEntity.getCityName().equals(addressEntityList.get(cityPosition1).getChildren().get(x2).getName())) {
                            cityPosition2 = x2;
                            break;
                        }
                    }
                }
                if (mEntity.getAreaName() != null) {
                    for (int x3 = 0; x3 < opt3.size(); x3++) {
                        if (mEntity.getAreaName().equals(addressEntityList.get(cityPosition1).getChildren().get(cityPosition2).getChildren().get(x3).getName())) {
                            cityPosition3 = x3;
                            break;
                        }
                    }
                }
            }
            mHandler.sendEmptyMessage(MSG_LOAD_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void initJsonDataJg() {
        try {
            //城市列表
            @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") List<AddressEntity<List<AddressEntity>>> cityList;
            //区域列表
            List<List<AddressEntity>> areaList;
            for (int x = 0; x < jgAddressEntityList.size(); x++) {
                cityList = new ArrayList<>();
                areaList = new ArrayList<>();
                if (mEntity != null && mEntity.getPrincipalHometown() != null && mEntity.getPrincipalHometown().size() > 0 && mEntity.getPrincipalHometown().get(0).equals(jgAddressEntityList.get(x).getNo())) {
                    wherePosition1 = x;
                }
                jgOpt2.add(jgAddressEntityList.get(x).getChildren());
                for (int i = 0; i < jgAddressEntityList.get(x).getChildren().size(); i++) {
                    cityList.add(jgAddressEntityList.get(x).getChildren().get(i));
                    List<AddressEntity> cityAreaList = new ArrayList<>();
                    //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                    if (jgAddressEntityList.get(x).getChildren().get(i).getChildren() == null
                            || jgAddressEntityList.get(x).getChildren().get(i).getChildren().size() == 0) {
                        cityAreaList.add(null);
                    } else {
                        cityAreaList.addAll(jgAddressEntityList.get(x).getChildren().get(i).getChildren());
                    }
                    areaList.add(cityAreaList);
                }
                jgOpt3.add(areaList);
            }
            if (mEntity != null) {
                if (mEntity.getPrincipalHometown() != null && mEntity.getPrincipalHometown().size() > 1) {
                    for (int x2 = 0; x2 < jgOpt2.size(); x2++) {
                        if (mEntity.getPrincipalHometown().get(1).equals(jgAddressEntityList.get(wherePosition1).getChildren().get(x2).getNo())) {
                            wherePosition2 = x2;
                            break;
                        }
                    }
                }
                if (mEntity.getPrincipalHometown() != null && mEntity.getPrincipalHometown().size() > 2) {
                    for (int x3 = 0; x3 < jgOpt3.size(); x3++) {
                        if (mEntity.getPrincipalHometown().get(2).equals(jgAddressEntityList.get(wherePosition1).getChildren().get(wherePosition2).getChildren().get(x3).getNo())) {
                            wherePosition3 = x3;
                            break;
                        }
                    }
                }
            }
            mHandler.sendEmptyMessage(MSG_LOAD_SUCCESS_JG);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void initJsonDataBz() {
        try {
            //城市列表
            @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") List<AddressEntity<List<AddressEntity>>> cityList;
            //区域列表
            List<List<AddressEntity>> areaList;
            for (int x = 0; x < bzAddressEntityList.size(); x++) {
                cityList = new ArrayList<>();
                areaList = new ArrayList<>();
                if (mEntity != null && mEntity.getAffBusinessAddress() != null && mEntity.getAffBusinessAddress().size() > 0 && mEntity.getAffBusinessAddress().get(0).equals(bzAddressEntityList.get(x).getNo())) {
                    bzPosition1 = x;
                }
                bzOpt2.add(bzAddressEntityList.get(x).getChildren());
                for (int i = 0; i < bzAddressEntityList.get(x).getChildren().size(); i++) {
                    cityList.add(bzAddressEntityList.get(x).getChildren().get(i));
                    List<AddressEntity> cityAreaList = new ArrayList<>();
                    //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                    if (bzAddressEntityList.get(x).getChildren().get(i).getChildren() == null
                            || bzAddressEntityList.get(x).getChildren().get(i).getChildren().size() == 0) {
                        cityAreaList.add(null);
                    } else {
                        cityAreaList.addAll(bzAddressEntityList.get(x).getChildren().get(i).getChildren());
                    }
                    areaList.add(cityAreaList);
                }
                bzOpt3.add(areaList);
            }
            if (mEntity != null) {
                if (mEntity.getAffBusinessAddress() != null && mEntity.getAffBusinessAddress().size() > 1) {
                    for (int x2 = 0; x2 < bzOpt2.size(); x2++) {
                        if (mEntity.getAffBusinessAddress().get(1).equals(bzAddressEntityList.get(bzPosition1).getChildren().get(x2).getNo())) {
                            wherePosition2 = x2;
                            break;
                        }
                    }
                }
                if (mEntity.getAffBusinessAddress() != null && mEntity.getAffBusinessAddress().size() > 2) {
                    for (int x3 = 0; x3 < bzOpt3.size(); x3++) {
                        if (mEntity.getAffBusinessAddress().get(2).equals(bzAddressEntityList.get(bzPosition1).getChildren().get(bzPosition2).getChildren().get(x3).getNo())) {
                            bzPosition3 = x3;
                            break;
                        }
                    }
                }
            }
            mHandler.sendEmptyMessage(MSG_LOAD_SUCCESS_BZ);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void initJsonDataSg() {
        try {
            //城市列表
            @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") List<AddressEntity<List<AddressEntity>>> cityList;
            //区域列表
            List<List<AddressEntity>> areaList;
            for (int x = 0; x < sgAddressEntityList.size(); x++) {
                cityList = new ArrayList<>();
                areaList = new ArrayList<>();
                if (mEntity != null && mEntity.getBusinessAddress() != null && mEntity.getBusinessAddress().size() > 0 && mEntity.getBusinessAddress().get(0).equals(sgAddressEntityList.get(x).getNo())) {
                    sgPosition1 = x;
                }
                sgOpt2.add(sgAddressEntityList.get(x).getChildren());
                for (int i = 0; i < sgAddressEntityList.get(x).getChildren().size(); i++) {
                    cityList.add(sgAddressEntityList.get(x).getChildren().get(i));
                    List<AddressEntity> cityAreaList = new ArrayList<>();
                    //如果无地区数据，建议添加空字符串，防止数据为null 导致三个选项长度不匹配造成崩溃
                    if (sgAddressEntityList.get(x).getChildren().get(i).getChildren() == null
                            || sgAddressEntityList.get(x).getChildren().get(i).getChildren().size() == 0) {
                        cityAreaList.add(null);
                    } else {
                        cityAreaList.addAll(sgAddressEntityList.get(x).getChildren().get(i).getChildren());
                    }
                    areaList.add(cityAreaList);
                }
                sgOpt3.add(areaList);
            }
            if (mEntity != null) {
                if (mEntity.getBusinessAddress() != null && mEntity.getBusinessAddress().size() > 1) {
                    for (int x2 = 0; x2 < sgOpt2.size(); x2++) {
                        if (mEntity.getBusinessAddress().get(1).equals(sgAddressEntityList.get(sgPosition1).getChildren().get(x2).getNo())) {
                            wherePosition2 = x2;
                            break;
                        }
                    }
                }
                if (mEntity.getBusinessAddress() != null && mEntity.getBusinessAddress().size() > 2) {
                    for (int x3 = 0; x3 < sgOpt3.size(); x3++) {
                        if (mEntity.getBusinessAddress().get(2).equals(sgAddressEntityList.get(sgPosition1).getChildren().get(sgPosition2).getChildren().get(x3).getNo())) {
                            sgPosition3 = x3;
                            break;
                        }
                    }
                }
            }
            mHandler.sendEmptyMessage(MSG_LOAD_SUCCESS_SG);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void showData(String name, List<String> no, String category) {
        mBind.etCategoryName.setText(name);
        mEntity.setCategoryNo1(no);
        mEntity.setCategory(category);
    }

    private void setBanZhuData() {
        //法人
        mBind.includeOne.etLegalPerson.setContent(mEntity.getLegalPerson());
        if (!TextUtils.isEmpty(mEntity.getLegalPerson())) {
            mBind.includeOne.etLegalPerson.setEnable(false);
        }
        //代征证号
        mBind.includeOne.etProxyCode.setContent(mEntity.getCertificateNumber());
        //经营地址
        mBind.includeOne.etManagementAddress.setContent(mEntity.getAffBusinessAddressName());
        if (!TextUtils.isEmpty(mEntity.getAffBusinessAddressName())) {
            mBind.includeOne.etManagementAddress.setEnable(false);
        }
        //隶属单位
        if (mEntity.getAffiliatedUnitPic() != null && !"".equals(mEntity.getAffiliatedUnitPic())) {
            Glide.with(this).load(mEntity.getAffiliatedUnitPic()).into(mBind.includeOne.img);
            mBind.includeOne.img.setVisibility(View.VISIBLE);
        }
    }

    public void setTeamIntroduceData(SelfTeamIntroduceEntity data) {
        mEntity = data;
        try {
            TransObjectUtils.transObject(data);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        int userType = SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0);
        if (userType == 0) {
            mEntity.setCompanyNo(null);
            mEntity.setCompanyName(null);
        } else if (userType == 1) {
            mEntity.setUserNo(null);
            mEntity.setUserName(null);
        }

        String[] sp = data.getCategoryNo().split("\\|");
        mEntity.setCategoryNo1(new ArrayList<>(Arrays.asList(sp)));
        if (TextUtils.isEmpty(data.getCompanyNo()) || "0".equals(data.getCompanyNo())) {
            isCompanyRole = false;
            mBind.llCooperationCompany.setVisibility(View.GONE);
            mBind.includeOne.layout.setVisibility(View.VISIBLE);
            mBind.etTeamType.setContent("班组工队");
            mBind.includeOne.etManagementAddress.setContent(mEntity.getAffBusinessAddressName());
            if (!TextUtils.isEmpty(mEntity.getAffBusinessAddressName())) {
                haveAddress = true;
            }
            setBanZhuData();
        } else {
            if (data.getTeamType() == 0) {
                mBind.llCooperationCompany.setVisibility(View.VISIBLE);
                mBind.includeOne.layout.setVisibility(View.GONE);
                mBind.etTeamType.setContent("施工队");
                //经营地址
                mBind.cooperationAddress.setContent(mEntity.getBusinessAddressName());
                if (!TextUtils.isEmpty(mEntity.getBusinessAddressName())) {
                    haveAddress = true;
                }
            } else {
                mBind.llCooperationCompany.setVisibility(View.GONE);
                mBind.etTeamType.setContent("班组工队");
                mBind.includeOne.layout.setVisibility(View.VISIBLE);
                mBind.includeOne.etManagementAddress.setContent(mEntity.getAffBusinessAddressName());
                if (!TextUtils.isEmpty(mEntity.getAffBusinessAddressName())) {
                    haveAddress = true;
                }
                setBanZhuData();
            }
        }
        mEntity.setLegalName(data.getLegalName());
        mEntity.setBusinessLicense(data.getBusinessLicense());
        mEntity.setLegalPhone(data.getLegalPhone());
        mEntity.setCreditCode(data.getCreditCode());
        mEntity.setLegalComName(data.getLegalComName());
        mEntity.setRegisteredCapital(data.getRegisteredCapital());
        mEntity.setFilePath(data.getFilePath());
        mEntity.setTrustCompany(data.getTrustCompany());
        mEntity.setBusinessAddressName(data.getBusinessAddressName());
        mEntity.setBusinessAddress(data.getBusinessAddress());
        mEntity.setBusinessAddress1(data.getBusinessAddress1());
        mEntity.setPrincipalHometownStr(data.getPrincipalHometownStr());
        mEntity.setAffBusinessAddressStr(data.getAffBusinessAddressStr());
        mBind.setViewModel(data);
        if (!TextUtils.isEmpty(mEntity.getLegalComName())) {
            mBind.cooperationCompanyname.setEnable(false);
        }

        if (!TextUtils.isEmpty(mEntity.getLegalName())) {
            mBind.cooperationName.setEnable(false);
        }

        if (!TextUtils.isEmpty(mEntity.getLegalPhone())) {
            mBind.cooperationPhone.setEnable(false);
        }

        if (!TextUtils.isEmpty(mEntity.getRegisteredCapital())) {
            mBind.cooperationCapital.setEnable(false);
        }

        if (!TextUtils.isEmpty(mEntity.getCreditCode())) {
            mBind.cooperationCode.setEnable(false);
        }

        if (!TextUtils.isEmpty(data.getAffiliatedUnitPic())) {
            mBind.includeOne.etCompanyName.setContent(data.getAffiliatedUnitPic());
            mBind.includeOne.etCompanyName.setEnable(false);
        }
        mBind.etAddress.setContent(data.getProvinceName() + data.getCityName() + data.getAreaName());
        if (!TextUtils.isEmpty(data.getAvatarAddress())) {
            Glide.with(getActivity()).load(data.getAvatarAddress()).into(mBind.ivPackerAvatar);
        }
        mAdapter1.setDatas(data.getBusinessScopes());
        StringBuilder stringBuilder = new StringBuilder();
        for (SelfTeamIntroduceEntity.ServiceAreasBean serviceArea : data.getServiceAreas()) {
            stringBuilder.append("/").append(serviceArea.getName());
        }
        stringBuilder.delete(0,1);
        mBind.etArea.setText(stringBuilder.toString());
        mBind.etArea.setHint("");
        if ("0".equals(teamTypes)) {
            if (!TextUtils.isEmpty(data.getBusinessLicense())) {
                Glide.with(getActivity()).load(data.getBusinessLicense()).into(mBind.cooperationBusinessLicense);
                mBind.cooperationBusinessLicense.setVisibility(View.VISIBLE);
            }
            mPicAdapter.setData(data.getFilePath());
        }
        //籍贯
        mBind.etWhere.setContent(mEntity.getPrincipalHometownName());
        //性别
        if ("0".equals(mEntity.getPrincipalSex())) {
            mBind.etSex.setContent("男");
        } else if ("1".equals(mEntity.getPrincipalSex())) {
            mBind.etSex.setContent("女");
        }
        //民族
        mBind.etNation.setContent(mEntity.getPrincipalNationName());

    }

    public void setUrlView(String url) {
        WebViewX5HostActivity.start(SelfTeamIntroduceActivity.this, url);
        finish();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mCompanyType = SharedPreferenceUtil.getInstance().getSaveIntData(SharedPreferenceUtil.COM_TYPE, 0);
    }
}
